/**
 * related to addressselect.ui
 * 
 * @Author : wzgl5533
 * @Timestamp : 2017-07-23
 */
var dojs = require("dojs");
var do_Page = sm("do_Page");
var do_Global = sm("do_Global");

var root = ui("root");
var do_ALayout_picker = ui("do_ALayout_picker");
var do_Picker_province = ui("do_Picker_province");
var do_Picker_city = ui("do_Picker_city");
var do_Picker_district = ui("do_Picker_district");
var do_Button_cancel = ui("do_Button_cancel");
var do_Button_ok = ui("do_Button_ok");
var dynamicButton;
var isRight = false;
//初始时要隐藏
root.visible = false;
//订阅显示view的消息
do_Page.on("showView", function() {
	if(! isRight)
	obtainAddressInfo.obtainAddressInfo();
	
	root.show("slide_l2r",200,function(){
		do_ALayout_picker.show("slide_b2t",500);
	});
	
});
//点击其它区域，则隐藏关闭当前View
root.on("touch", function() {

	do_ALayout_picker.hide("slide_t2b", 500, function(data, e) {
		root.hide("slide_r2l",200);
	});
});
//添加效果
dynamicButton = "dynamicButton";
dojs.style.css(do_Button_cancel, dynamicButton);
dojs.style.css(do_Button_ok,dynamicButton);
//取消按钮
dojs.page.onTouch(do_Button_cancel,function(){
	do_ALayout_picker.hide("slide_t2b", 400, function(data, e) {
		root.hide("slide_r2l",200);
	});
});
//确认按钮
dojs.page.onTouch(do_Button_ok,function(){
	confirmAddress();
});
//屏蔽这个布局的是touch事件
dojs.page.onTouch(do_ALayout_picker,function(){});
//解析地址信息
var obtainAddressInfo = require("source://modules/addressselect/test");
obtainAddressInfo.obtainAddressInfo();

var presenter = require("source://modules/addressselect/presenter");
//初始化消息
do_Page.on("initAddressSelect", function(data) {

	var view = {
		do_Picker_province : do_Picker_province,
		do_Picker_city : do_Picker_city,
		do_Picker_district : do_Picker_district,
		do_ALayout_picker:do_ALayout_picker
	};
	presenter.initView(data, view)
})
//订阅地址解析完成消息
do_Page.on("addressParseCompleted", function(data) {

	isRight = data.iscomplete;
	presenter.initAddress(data);
});
//----------------------------------------------------
//确认地址
function confirmAddress() {
	
	do_Page.fire("finalAddress", presenter.getFinalAddress());
	do_ALayout_picker.hide("slide_t2b", 400, function(data, e) {
		root.hide("slide_r2l",200);
	});
}